package app.qrcode.browser.hearttoheart.fragments

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import app.qrcode.browser.hearttoheart.R
import app.qrcode.browser.hearttoheart.adapters.Student
import app.qrcode.browser.hearttoheart.adapters.StudentAdapter
import app.qrcode.browser.hearttoheart.databinding.FragmentClassControlBinding
import kotlinx.android.synthetic.main.fragment_class_control.*


/**
 * A simple [Fragment] subclass.
 * Use the [classControlFragment.newInstance] factory method to
 * create an instance of this fragment.
 */
class ClassControlFragment : Fragment() {
    private var _binding: FragmentClassControlBinding? = null

    private val binding get() = _binding!!

    private val studentAdapter by lazy { StudentAdapter() }


    private var studentList: ArrayList<Student> = ArrayList()
    // TODO: Rename and change types of parameters

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {

        _binding = FragmentClassControlBinding.inflate(inflater, container, false)
        val root: View = binding.root
        initRecyclerView()
        // Inflate the layout for this fragment
        return root
    }

    fun initRecyclerView() {
        studentList.add(Student(null, null, null))
        studentList.add(Student(null, null, null))
        studentList.add(Student(R.mipmap.three, "杨正恒", null))
        studentList.add(Student(R.mipmap.three, "李逸凯", null))
        studentList.add(Student(R.mipmap.three, "尹政儒", null))
        studentList.add(Student(R.mipmap.girl, "李潇", null))
        studentList.add(Student(R.mipmap.three, "林生香", null))
        studentList.add(Student(R.mipmap.girl, "林家风", null))
        studentList.add(Student(R.mipmap.three, "杨镇", null))
        studentList.add(Student(R.mipmap.girl, "欧美玲", null))
        studentList.add(Student(R.mipmap.girl, "吕文姬", null))
        val studLayoutManager = LinearLayoutManager(context)
        binding.classControlList.layoutManager = studLayoutManager
        binding.classControlList.adapter = studentAdapter
        studentAdapter.updateList(studentList)
    }


}